package cn.nbt.busManage.model.vo;


import cn.nbt.busManage.model.dto.MenuDto;
import cn.nbt.busManage.model.dto.RoleDto;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Getter
public class RoleVo implements Serializable {
    private final Integer id;
    private final String roleName;
    private final Integer status;
    private final List<MenuVo> menuVos;

    public RoleVo(RoleDto roleDto){
        this.id = roleDto.getId();
        this.roleName = roleDto.getRoleName();
        this.status = roleDto.getStatus();
        List<MenuDto> menus = roleDto.getMenus();
        ArrayList<MenuVo> arrayList = new ArrayList<>();
        for (MenuDto menuDto : menus){
            arrayList.add(new MenuVo(menuDto));
        }
        this.menuVos = arrayList;
    }

    @JsonCreator
    public RoleVo(
            @JsonProperty("id") Integer id,
            @JsonProperty("roleName")  String roleName,
            @JsonProperty("status") Integer status,
            @JsonProperty("menuVos") List<MenuVo> menuVos
    ) {
        this.id = id;
        this.roleName = roleName;
        this.status = status;
        this.menuVos = menuVos;
    }
}
